package top.hkyzf.study.leetcode.array;

import org.junit.Test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

/**
 * @author 朱峰
 * @date 2022-2-14 12:49
 */
public class 矩阵置零_73 {
    public void setZeroes(int[][] matrix) {
        Set<Integer> rowSet = new HashSet<>();
        Set<Integer> colSet = new HashSet<>();
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == 0) {
                    rowSet.add(i);
                    colSet.add(j);
                }
            }
        }
        for (Integer next : rowSet) {
            for (int i = 0; i < matrix[0].length; i++) {
                matrix[next][i] = 0;
            }
        }
        for (Integer next : colSet) {
            for (int i = 0; i < matrix.length; i++) {
                matrix[i][next] = 0;
            }
        }
    }

    @Test
    public void testSetZeros () {
        int[][] matrix = {{0,1,2,0},{3,4,5,2},{1,3,1,5}};
        setZeroes(matrix);
        for (int[] ints : matrix) {
            System.out.println(Arrays.toString(ints));
        }
    }
}
